<?php
namespace app\friend\controller;
use think\Controller;
use think\Db;
use think\Session;

class Requested extends Controller
{
    public function index()
    {
        $id = Session::get('id');
        // var_dump($id);
        //当前用户信息
        $user = Db::table('user_info')->where('uid',$id)->find();
        // var_dump($user);

        //当前用户全部好友
        $friends = Db::table('friend')->alias('f')->join('user_info u','u.uid = f.fid')->where('f.uid',$id)->where('f.status',0)->select();
        // $friends = Db::table('user_info')->where('uid','neq',$id)->select();
        // var_dump($friends);

        $this->assign('user',$user);
        $this->assign('friends',$friends);

        return $this->fetch('index/requested');
        
    }

    public function agree()
    {
        $uid = input('uid');
        // var_dump($uid);
        //通过好友请求,并改变friend表的状态值
        Db::table('friend')->where('uid',Session::get('id'))->where('fid',$uid)->update(['status'=>1]);
        Db::table('friend')->where('fid',Session::get('id'))->where('uid',$uid)->update(['status'=>1]);
    }
}
